package com.lyh;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Main extends JFrame {

    private final JTabbedPane jTabbedPane = new JTabbedPane();

    private JPanel jPanel;
    private JPanel jsonPanel;
    private JPanel dwhPanel;

    public Main(){
        setSize(new Dimension(600,800));
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        initHomePanel();
        jTabbedPane.addTab("first page",null,jPanel,"see here");

        initJsonPane();

        initDwhPane();


        add(jTabbedPane);
    }
    public void initJsonPane(){
        jsonPanel = new JPanel();

    }
    public void initDwhPane(){
        dwhPanel = new JPanel();
    }

    public void initHomePanel(){
        jPanel = new JPanel();
        jPanel.setLayout(new BoxLayout(jPanel,BoxLayout.Y_AXIS));

        JButton button1 = new JButton("json tool");
        JButton button2 = new JButton("dwh tool");

        button1.addActionListener(e -> {
            if (-1 == jTabbedPane.indexOfComponent(jsonPanel)){
                jTabbedPane.addTab("json tool",null,jsonPanel);
            }
            jTabbedPane.setSelectedComponent(jsonPanel);
        });

        button2.addActionListener(e -> {
            if (-1 == jTabbedPane.indexOfComponent(dwhPanel)){
                jTabbedPane.addTab("dwh tool",null,dwhPanel);
            }
                jTabbedPane.setSelectedComponent(dwhPanel);
        });


        button1.setForeground(Color.WHITE);
        button2.setForeground(Color.WHITE);
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                button1.setBackground(Color.BLACK);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                button1.setBackground(null);
            }
        });
        jPanel.add(button1);
        button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                button2.setBackground(Color.BLACK);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                button2.setBackground(null);
            }
        });
        jPanel.add(button1);
        jPanel.add(button2);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(()->{
            new Main().setVisible(true);
        });
    }
}
